package com.elasticsearch.controller;

import com.alibaba.fastjson.JSONObject;
import com.elasticsearch.service.ElasticsearchService;
import com.elasticsearch.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;


/**
 * @author: yyx
 * @Date: 2021-2-2
 */
@RestController
@RequestMapping("/es")
public class ElasticsearchController {
    @Resource
    ElasticsearchService service;
    /**
     * es通用存储
     * */
    @PostMapping("/save")
    public R save(@RequestBody JSONObject jsonObject) throws IOException {
        String id = service.save(jsonObject);
        return R.data(id);
    }

    /**
     * es多条件模糊查询通
     * */
    @PostMapping("/getFuzzyQuery")
    public R getFuzzyQuery(@RequestBody JSONObject jsonObject) throws IOException {
        return R.data(service.getFuzzyQuery(jsonObject));
    }

    /**
     * es通用获取
     * */
    @PostMapping("/get")
    public R get(@RequestBody JSONObject jsonObject) throws IOException {
        return R.data(service.get(jsonObject));
    }

    /**
     * es通用修改
     * */
    @PostMapping("/update")
    public R update(@RequestBody JSONObject jsonObject, @RequestParam String id) throws IOException {
        return R.data(service.update(jsonObject,id));
    }

//    /**
//     * es通用删除
//     * */
//    @PostMapping("/delete")
//    public R delete( @RequestParam String ids) throws IOException {
//        return R.data(service.delete(ids));
//    }


}